/*
 * =====================================================================================
 *
 *       Filename:  http.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  02/10/2018 05:40:10 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __HTTP_H__
#define __HTTP_H__
#include <curl/curl.h>
#include "common.h"

/* Global information, common to all connections */
typedef struct _GlobalInfo
{
	struct ev_loop *loop;
	struct ev_timer timer_event;
	CURLM *multi;
	int still_running;
	FILE *input;
} GlobalInfo;

typedef void (*recvcb)(void *);
/* Information associated with a specific easy handle */
typedef struct _ConnInfo
{
	CURL *easy;
	char *url;
	char *data;
	recvcb recvcb;
	void *recv;
	GlobalInfo *global;
	char error[CURL_ERROR_SIZE];
} ConnInfo;

/* Information associated with a specific socket */
typedef struct _SockInfo
{
	curl_socket_t sockfd;
	CURL *easy;
	int action;
	long timeout;
	struct ev_io ev;
	int evset;
	GlobalInfo *global;
} SockInfo;

GlobalInfo *http_multi_init(EV_P);
void http_multi_send(GlobalInfo *g, char *url, char *data, void *callback, void *recv, recvcb cb);
size_t just_return( char *ptr, size_t size, size_t  nmemb,  void *userdata);
int  http_send(char *url, char *data, void *callback, struct curl_slist * headers);
#endif /* __HTTP_H__ */
